<?php
namespace App\Admin\Models;
use Common\BaseModel;
class Questions extends BaseModel
{
    protected $res;
    protected $redis_key="admin_";
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_questions');
    }



    public function question_list($params)
    {
        $condition = "question like '%{$params['keywords']}%' AND isshow=1";
        if(isset($params['cateid']) && !empty($params['cateid'])){
            $condition .= " AND qcat_id='{$params['cateid']}'";
        }
        $cate_list = $this::find(
            array(
                $condition,
                "order" => 'sort asc',
            ));
        return $cate_list;
    }


    /**
     * 统计某个分类下面有多少文章
     * @param $params
     * @return bool
     */
    public function mycount($cate_id){
        $condition = "qcat_id={$cate_id}";
        $count_number = $this::count(
            array(
                $condition,
                "columns" => 'id',
            ));
        return $count_number;
    }


    public function save_question($params){
        $result = $this::save($params);
        if($result){
            return true;
        }else{
            return false;
        }
    }



    /**
     * 根据营销id获取营销
     */
    public function find_first_by_Id($id){
        if(empty($id)){
            return '';
        }
        $cate_info = $this->findFirstById($id);
        if($cate_info){
            return $cate_info->toarray();
        }else{
            return [];
        }
    }


}
